package No1_100.No61_70.PlusOne_66;

public class Solution {
	public static int[] plusOne(int[] digits) {
		int flag = 0;
        for (int i = digits.length-1; i >= 0; i--) {
			digits[i] ++;
			if (digits[i] == 10) {
				digits[i] = 0;
				flag = 1;
			}
			else{
				flag = 0;
				break;
			}
		}
        if (flag == 1) {
			int[] back = new int[digits.length+1];
			back[0] = 1;
			for (int i = 1; i < back.length; i++) {
				back[i] = digits[i-1];
			}
			return back;
		}
        else{
        	return digits;
        }
    }
	
	public static void main(String[] args) {
		int[] a = new int[2];
		a[0] = 9;
		a[1] = 9;
		int[] result = plusOne(a);
		for (int i = 0; i < result.length; i++) {
			System.out.print(result[i]);
		}
	}
}
